package com.learn.liquibase.service;

import com.learn.liquibase.entity.Person;
import com.learn.liquibase.entity.PersonExample;
import com.learn.liquibase.mapper.PersonMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * TODO
 *
 * @author zhousiqi
 * @version 1.0.0
 * @date 2019/2/27 13:59
 */
@Service
public class PersonService {

    @Resource
    private PersonMapper personMapper;

    /**
     * 根据id查询person
     * @param id id
     * @return person
     */
    @Transactional(readOnly = true)
    public Person getPersonById(Long id){
        PersonExample example = new PersonExample();
        example.createCriteria().andIdEqualTo(id);
        return personMapper.selectByExample(example).stream().findAny().orElse(null);
    }
}
